package com.liuyanzhao.blog.controller.Home;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liuyanzhao.blog.entity.Article;
import com.liuyanzhao.blog.entity.Comment;
import com.liuyanzhao.blog.service.ArticleService;
import com.liuyanzhao.blog.service.CommentService;

/**
 * 
 * @author jingtai sun
 *  [评论功能的controller]
 * @CrateTime: 2019年6月22日
 */

@Controller
public class CommentController {
	@Autowired
	private CommentService commentService;

	@Autowired
	private ArticleService articleService;
	
	/**
	 * 
	 *  [添加评论]
	 * @param request
	 * @param comment
	 * @throws Exception
	 * @Return: void
	 * @author jingtai sun
	 * @CreateDate: 2019年6月22日 下午9:31:04
	 */
	@RequestMapping(value = "/comment/insert",method = {RequestMethod.POST})
	@ResponseBody
	public void insertComment(HttpServletRequest request,Comment comment) throws Exception {
		/**
		 * 添加评论
		 */
		comment.setCommentCreateTime(new Date());
		commentService.insertComment(request,comment);
		/**
		 * 更新文章的评论数
		 */
		Article article = articleService.getArticleById(null,comment.getCommentArticleId());
		articleService.updateCommentCount(article.getArticleId());
	}


}
